<template>
  <div class="content-box">
    <nav-title title="教育经历" />
    <edit-date-line :important="true" label="开始时间" v-model="edus.startDt"></edit-date-line>
    <edit-date-line :important="true" label="结束时间" v-model="edus.endDt"></edit-date-line>
    <edit-option-line label="学校名称" :important="true" @on-change="choseSchool" :vals="schools" v-model="edus.cSchool"></edit-option-line>
    <edit-line label="其他院校" :important="false" v-model="edus.cSchoolOth" v-if="edus.cSchool=='其他'"></edit-line>
    <edit-option-line label="是否985" :important="true" :vals="lcList" v-model="edus.cIs985" :xreadonly="edus.cSchool!='其他'"></edit-option-line>
    <edit-option-line label="是否211" :important="true" :vals="lcList" v-model="edus.cIs211" :xreadonly="edus.cSchool!='其他'"></edit-option-line>
    <edit-option-line label="就学类型" :important="true" :vals="cTolType2Val" v-model="edus.cTolType2"></edit-option-line>
    <edit-option-line label="学历" :important="true" :vals="educationList" v-model="edus.cEduciton"></edit-option-line>
    <edit-option-line label="学位" :important="true" :vals="degreeList" v-model="edus.cDegree"></edit-option-line>
    <edit-line label="专业" :important="true" v-model="edus.cMajor"></edit-line>
    <edit-line label="学制" type="number" :important="true" v-model="edus.cSchoolSystem"></edit-line>
    <edit-option-line label="是否最高学历" :important="true" :vals="lcList" v-model="edus.cYesNo1"></edit-option-line>
  
    <div class="btn_region">
      <div class="submit-btn" @click="save">保存</div>
      <div class="remove-btn" @click="remove"> 删除 </div>
    </div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditDateLine from '../../../../components/basic/EditDateLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { saveEducation,delEducation,getDicItem,getSchools } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
     EditOptionLine, EditDateLine, EditLine
  },
  mounted(){
    //获取字典
    this.getDic();
    if(this.$store.state.hid){
      this.edus.rsHireId = this.$store.state.hid
      this.eduDel.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      edus:{
        rsHireId: '',
      },

      eduDel:{
        rsHireId: '',
        cSeqno:''
      },
      schools:[],
      sch211:{},
      sch985:{},
      educationList: [],
      degreeList: [],
      cTolType2Val:[],
      lcList: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
    }
  },
  created() {
    this.getEdus()
  },
  methods: {
    getDic(){
      //学历字典
      CommonUtil.loadDic(this.educationList, 'C_EDUCITON', "xlatshortname","fieldvalue");//学历字典
      CommonUtil.loadDic(this.degreeList, 'C_DEGREE', "xlatshortname","fieldvalue");//学位字典
      CommonUtil.loadDic(this.cTolType2Val, 'C_TOL_TYPE2', "xlatshortname","fieldvalue");//学历字典
      var _this = this
      //学校
      getSchools().then(res => {
        res.retData.forEach((val) => {
          _this.schools.push({value: val.cSchool, key: val.cSchool})
          _this.sch211[val.cSchool]=val.cIs211
          _this.sch985[val.cSchool]=val.cIs985
        });
      })
    },
    choseSchool(newSchool){
      console.error(newSchool)
      if(newSchool == '其他'){
        this.edus.cIs211 = 'N'
        this.edus.cIs985 = 'N'
      } else {
        this.edus.cIs211 = this.sch211[newSchool]
        this.edus.cIs985 = this.sch985[newSchool]
      }
    },
    save() {
      const that = this
      if(!CommonUtil.valid(this, this.edus,"startDt","请选择开始时间") 
        || !CommonUtil.valid(this, this.edus,"endDt","请选择结束时间") 
        || !CommonUtil.valid(this, this.edus,"cSchool","请输入学校名称")
        || !CommonUtil.valid(this, this.edus,"cTolType2","请选择就学类型") 
        || !CommonUtil.valid(this, this.edus,"cEduciton","请选择学历")  
        || !CommonUtil.valid(this, this.edus,"cDegree","请选择学位") 
        || !CommonUtil.valid(this, this.edus,"cMajor","请输入专业") 
        || !CommonUtil.valid(this, this.edus,"cSchoolSystem","请输入学制")
        || !CommonUtil.valid(this, this.edus,"cYesNo1","请选择是否最高学历")  
        ){
        return;
      }
      if(this.edus.cSchool == '其他' && !this.edus.cSchool){
          this.$vux.alert.show({
            title: '提示',
            content: '请输入学校名称'
          })
          return;
      }
      if(!this.edus.cSchoolSystem) {
        this.edus.cSchoolSystem = 0
      }


      saveEducation(json2Form(that.edus)).then(res => {
        if(res && res.retCode === '000000' ){
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })
        }else{
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {
      const _this = this;

      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delEducation(json2Form(_this.eduDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                  _this.$router.push('/informationCollection/userInfo');
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }
            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })

          }
        })
    },
    getEdus() {
      if(this.$route.params.edult){
        this.edus = this.$route.params.edult
        if(this.edus.cSchoolSystem == 0) {
          this.edus.cSchoolSystem = ''
        }
        this.eduDel.cSeqno = this.$route.params.edult.cSeqno
        console.log(this.$route.params.edult.nta)
      }
      CommonUtil.fillDateEmpty(this.edus, ['startDt', 'endDt'])
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
